package game.controller
{
	import assets.EmbededAssets;
	import flash.display.Bitmap;
	import game.constants.ApplicationNotification;
	import game.model.texture.TextureProxy;
	import game.model.texture.vo.TextureVO;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import starling.textures.Texture;
	
	/**
	 * ...
	 * @author Thot
	 */
	
	public class LoadGameDataCommand extends SimpleCommand
	{
		override public function execute( notification:INotification ):void
		{
			var textureProxy:TextureProxy = facade.retrieveProxy( TextureProxy.NAME ) as TextureProxy;
			var list:Array = EmbededAssets.TEXTURES_LIST;
			var i:int = 0;
			var max:int  = list.length;
			var vo:TextureVO;
			
			for ( ; i < max; i++ )
			{
				vo = new TextureVO();
				vo.id = list[i].id;
				vo.name = list[i].name;
				vo.data = Texture.fromBitmap( new list[i].clazz() as Bitmap );
				textureProxy.addTexture( vo );
				
				sendNotification( ApplicationNotification.LOAD_GAME_DATA_PROGRESS, { "progression":(int)(i / max * 100) } );
			}
			sendNotification( ApplicationNotification.LOAD_GAME_DATA_COMPLETE, { "progression":100 } );
		}
	}

}